import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';

export default function getRosterData(language) {
    const {listRefVal} = this.state;
    if (!listRefVal.refpk) return;
    const {
        include_child_orgs,
        queryOid,
        orgVal,
        show_on_job_psn,
        tree_node_id,
        rosterPks,
        search
    } = this.props;


    let postData = {
        logic: 'and',
        psnjob_pks: rosterPks,
        oid: queryOid,
        pk_org: orgVal.refpk,
        template_id: listRefVal.refpk,
        showHisGrp: include_child_orgs,
        show_his_key_psn: show_on_job_psn,
        pk_keypsn_group: tree_node_id,
        ...search.getAllSearchData('ncc60071025query')
    };

    return proFetch({
        url: '/nccloud/hrhi/keypsn/KeyPsnListReptQueryAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                const columns = res.data.table.map(item => {
                    return {
                        title: item.name, dataIndex: item.code, key: item.code, width: '120px'
                    }
                });
                columns.unshift({
                    title: language['hi6007-000036'], dataIndex: 'numberindex', key: 'numberindex', width: '100px'
                });
                res.data.data.forEach((item, index) => item.numberindex = index + 1);

                this.setState({
                    columns,
                    data: res.data.data
                });
            } else {
                this.setState({
                    columns: [],
                    data: []
                });
            }
        });
}
